package com.cyq.day21.managementsystem;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChooseFrame extends JFrame {
    private JTextArea area;
    private JTextField textField;
    private JButton button;
    private JPanel panel;
    Employee[] employees = new Employee[50];

    public ChooseFrame() {
        employees[0] = new Employee("aaaaa", "12345", "员工");
        employees[1] = new Employee("admin", "12345", "管理员");
        employees[2] = new Employee("bbbbb", "12345", "员工");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("选择界面");
        setBounds(200, 100, 500, 500);
        area = new JTextArea();
        area.setEditable(false);
        area.setText("欢迎使用菜鸟驿站管理系统" + "\n" + "请输入选项" + "\n" + "1.登录系统" + "\n" + "2.退出系统" + "\n");
        add(area);
        textField = new JTextField(20);
        button = new JButton("确定");
        panel = new JPanel();
        panel.add(textField);
        panel.add(button);
        add(BorderLayout.SOUTH, panel);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if ("1".equals(textField.getText())) {
                    LoginFrame loginFrame = new LoginFrame(employees);
                    loginFrame.setVisible(true);
                    ChooseFrame.this.dispose();
                } else if ("2".equals(textField.getText())) {
                    JOptionPane.showMessageDialog(null, "谢谢使用再见");
                    System.exit(0);
                } else {
                    JOptionPane.showMessageDialog(null, "请输入正确的选项");
                }
            }
        });

    }
}
